<?php

/*
 * This file is part of PHP CS Fixer.
 * (c) kcloze <pei.greet@qq.com>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace app\index\Controller;
use think\Db;
use Kcloze\Jobs\Message\Message;


class JobAction extends BaseAction{
    
   public function _initialize(){
        parent::_initialize();
    }
    
    public  function test1($a, $b)
    {  
        echo $this->toColor('********************************开始***********************************'.PHP_EOL);
        
        
        
        
        print_r(Db::connect('db1'));
        
        
        
        $t1 = microtime(true);
        $m = $this->memory_usage();
        $result =  Db::connect('db1')->name('seller_commission_bill')->select();
        
        foreach ($result as $value) {
          
        }
        
        $result = Db::name('code')->find();
        
        $data['name'] = 'test'.time();
        $data['t'] = time();
        $data['ip'] = "222.180.210.250";
        $data['log'] = "test".date('Y-m-d :h:i:s',time());
         
        $result =  Db::table('xyh_log')->data($data)->insert();	
        
        
        $t2 = microtime(true);
        echo '耗时'.round($t2-$t1,3).'秒'.PHP_EOL;
        echo 'Now memory_get_usage: ' .$m.'*****'.$this->memory_usage().'*******'.($this->memory_usage()- $m).PHP_EOL.'时间：'.date('Y-m-d h:i:s',time()).PHP_EOL.PHP_EOL.PHP_EOL;
        
    
        
       echo $this->toColor('********************************结束***********************************'.PHP_EOL);
       
        
        
        
        
    }
    public function toColor($in){
        
        if(is_numeric($in)){
            $r=($in>-1)?"\033[31m{$in}\033[0m":$in;
        }else{
            $r="\033[31m{$in}\033[0m";
        }
        return $r;
    }
   public function memory_usage() { 
        $memory     = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024, 2).'KB'; 
        return $memory; 
    } 
}
